@extends('admin.layout.global')

@section('css-plugins')
    <link href="{{ asset('style/plugins/bootstrap-switch/css/bootstrap3/bootstrap-switch.min.css') }}" rel="stylesheet">
    <link href="{{ asset('style/plugins/chosen_v1.2.0/chosen.min.css') }}" rel="stylesheet">
    <link href="{{ asset('style/plugins/multi-select/css/multi-select.css') }}" rel="stylesheet" type="text/css" />
@endsection

@section('css')
    <link href="{{ asset('style/admin/css/custom.css') }}" rel="stylesheet">
    <style>
        #iconfile {
            width: 100%;
            height: 100%;
            opacity: 0;
            position: relative;
            top: -250px;
            left: 0px;
            z-index: 100;
        }
    </style>
@endsection

@section('js-plugins')
    <script src="{{ asset('style/plugins/bootstrap-switch/js/bootstrap-switch.min.js') }}"></script>
    <script src="{{ asset('style/plugins/chosen_v1.2.0/chosen.jquery.min.js') }}"></script>
    <script src="{{ asset('style/plugins/multi-select/js/jquery.multi-select.js') }}" type="text/javascript"></script>
    <script src="{{ asset('style/plugins/quicksearch/jquery.quicksearch.js') }}" type="text/javascript"></script>
@endsection

@section('js')
    <script src="{{ asset('style/admin/js/pages/blankon.form.element.js') }}"></script>
    <script src="{{ asset('style/plugins/ajaxUpload/ajaxupload.js') }}"></script>
    <script>
        $(function(){
            $("[type='checkbox']").bootstrapSwitch();
        });
    </script>
    <script>
        function adminupload(names,idd){
            var oldico = $("#icoinput").val();
            return {
                // 提交目标
                action: "{{ action('Admin\Shop\SlideController@postUpload') }}",
                data: {"_token":"{{ csrf_token() }}","_oldico":oldico},
                // 服务端接收的名称
                name: names,
                // 自动提交
                autoSubmit: true,
                // 上传完成之后
                onComplete: function (file, response) {
                    var response = JSON.parse(response);
                    console.log(response);
                    if (response=="") {
                        $("#errorico").html("上传的类型不符合!");
                    }else {
                        $("#errorico").html("");
                        $(idd).attr("src", response.result);
                        $("#icoinput").val(response.thumb);
                    }
                }
            }
        }
    </script>
    <script>
        var oAjaxUpload = new AjaxUpload("iconfile", adminupload('icon','#iconsrc'));
    </script>
@endsection

@section('content')
    <div class="body-content animated fadeIn">
        <div class="row">
            <div class="col-md-4">
                <div class="panel rounded shadow" id="leftMove">
                    <div class="panel-heading">
                        <div class="pull-left">
                            <h3 class="panel-title">{{ last($HMENU)->name }}</h3>
                        </div><!-- /.pull-left -->
                        <div class="pull-right">
                        </div><!-- /.pull-right -->
                        <div class="clearfix"></div>
                    </div><!-- /.panel-heading -->
                    <div class="panel-body">
                        <form method="post">
                            <div class="form-body">
                                {!! csrf_field() !!}
                                <div class="form-group">
                                    <label class="control-label">标题<span class="asterisk">*</span></label>
                                    <input placeholder="" name="title" value="{{ old('title') }}" class="form-control" type="text">
                                    {!! getErrorMsg($errors, 'title') !!}
                                </div>
                                <div class="form-group">
                                    <label class="control-label">图片<span class="asterisk">*</span></label>
                                    <div id="fileupload">
                                        <div class="row fileupload-buttonbar">
                                            <div class="avatar-view fileinput-button" style="margin: 10px 13px; width: 375px; height: 250px;" title="点击更换缩略图">
                                                <img width="375" height="250" id="iconsrc" src="{{ action('ImgController@getPicture', ['sourceName' => 'no.png', 'size' => '375x250']) }}" alt="缩略图">
                                                <input type="hidden" id="icoinput" name="thumb" value="{{ old('thumb') }}">
                                                <input type="file" id="iconfile" name="icon" class="image-input">
                                            </div>
                                        </div>
                                    </div>
                                    <span class="help-block no-margin">幻灯比例必须为 <b style="color: red">375 x 250</b> </span>
                                    {!! getErrorMsg($errors, 'thumb') !!}
                                </div>
                                <div class="form-group">
                                    <label class="control-label">区域<span class="asterisk">*</span></label>
                                    <div class="input-group col-xs-6">
                                        <select data-placeholder="请选择店铺" name="storeID" class="chosen-select mb-15" tabindex="2">
                                            <option value=""></option>
                                            @foreach($store as $v)
                                                <option value="{{ $v->id }}" @if(old('storeID') && old('storeID') == $v->id) selected @endif>{{ $v->name }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    {!! getErrorMsg($errors, 'storeID') !!}
                                </div>
                                <div class="form-group">
                                    <label class="control-label">连接</label>
                                    <input placeholder="" name="link" value="{{ old('link') }}" class="form-control" type="text">
                                    {!! getErrorMsg($errors, 'link') !!}
                                </div>
                                <div class="form-group">
                                    <label>是否显示</label><br>
                                    <input type="checkbox" name="display" checked-false data-size="small" data-on-text="{{ getLang('Tips', 'showON') }}" data-off-text="{{ getLang('Tips', 'showOFF') }}" data-label-width="0" data-on-color="success" data-off-color="danger">
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <a href="{{ action('Admin\Shop\SlideController@getIndex') }}" class="btn btn-warning btn-sm btn-block"><i class="fa fa-reply"></i> <span class="bold">{{ getLang('Tips', 'rollBack') }}</span></a>
                                    </div>
                                    <div class="col-md-6">
                                        <button class="btn btn-primary btn-sm btn-block" type="submit"><i class="fa fa-check"></i>&nbsp;{{ getLang('Tips', 'submit') }}</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div><!-- /.panel-body -->
                </div><!-- /.panel -->
            </div>
        </div><!-- /.row -->
    </div>
@endsection